home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / 80x0393.zip / DE-ICE.ASM < prev    next >
Assembly Source File  |  1993-03-30  |  6KB  |  267 lines

  1. ;
  2. ; deice.asm by Inbar Raz
  3. ;
  4. ; Notice - this is for COM only
  5. ;
  6.  
  7.         .model  tiny
  8.         .code
  9.  
  10.         org    0100h
  11.  
  12. CODESTART       EQU     $
  13.  
  14. Start:  jmp     Begin
  15.  
  16. NewName db      'OPENED.COM', 000h
  17. Handle  dw      ?
  18. Old60   dd      ?
  19.  
  20. M_Prog  db      'DeIce - A program to extract executables compressed under ICE.'
  21.         db      00Dh, 00Ah
  22.         db      'By Inbar Raz, 2:401/100.1 or 2:403/123.42.'
  23. CrLf    db      00Dh, 00Ah, 024h
  24.  
  25.  
  26. AlgorithmSize   EQU     00200h
  27.  
  28. ; ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  29. ;
  30. ; First Breakpoint - Encryption Loop
  31.  
  32. CallerOff       EQU     word ptr ss:[bp+00002h]
  33. RetAddress      EQU     word ptr ss:[bp+00008h]
  34. HereCount db    2
  35.  
  36. New60   proc    far
  37.  
  38.         push    bp
  39.         mov     bp,sp
  40.  
  41.         dec     cx                      ; When CX=1, LOOP simply proceeds.
  42.         jnz     Wrong
  43.  
  44. ; By now, the encryption has been finished. Now we will replace the second
  45. ; loop also with a CD 02, and we will self-modify the routie so it would handle
  46. ; the second loop.
  47.  
  48. ; First, let's find the address for the next breakpoint
  49.  
  50.         push    ax
  51.         push    cx
  52.         push    dx
  53.         push    di
  54.         push    ds
  55.  
  56.         std
  57.         mov     cx,AlgorithmSize
  58.         mov     di,RetAddress
  59.         mov     al,001h
  60. Scan2:  repnz   scasb
  61.         or      cx,cx
  62.         jnz     NotDone
  63.         jmp     NotIce
  64.  
  65. NotDone:
  66.         cmp     word ptr es:[di+2],0FF2Eh ; The LOOP we are searching
  67.         jne     Scan2
  68.         cmp     word ptr es:[di+4],00A26h
  69.         jne     Scan2
  70.  
  71.         inc     di
  72.         inc     di
  73.         mov     ax,060CDh               ; Replace with INT 60
  74.         stosw
  75.  
  76.         mov     ax,02560h
  77.         push    cs
  78.         pop     ds
  79.         lea     dx,New60_
  80.         int     21h
  81.  
  82.         pop     ds
  83.         pop     di
  84.         pop     dx
  85.         pop     cx
  86.         pop     ax
  87.  
  88.         pop     bp
  89.  
  90.         iret
  91.  
  92. Wrong:  push    ax
  93.         mov     ax,CallerOff
  94.         sub     ax,00008h
  95.         mov     CallerOff,ax
  96.         pop     ax
  97.  
  98.         pop     bp
  99.         iret
  100.  
  101. New60   endp
  102.  
  103. ; ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  104.  
  105. New60_  proc    near
  106.  
  107.         int     3
  108.  
  109.         push    ds
  110.  
  111.         push    cs
  112.         pop     ds
  113.  
  114.         mov     ah,03Ch
  115.         mov     cx,00020h
  116.         lea     dx,NewName
  117.         int     21h
  118.  
  119.         jnc     Created
  120.  
  121.         call    Print
  122.         db      'Unable to create destination file.$'
  123.  
  124. Created:
  125.         mov     word ptr cs:[Handle],ax
  126.  
  127.         mov     bx,ax
  128.         mov     ah,040h
  129.         mov     cx,di
  130.         sub     cx,001ACh
  131.         mov     dx,si
  132.         pop     ds
  133.         int     21h
  134.  
  135.         mov     ah,03Eh
  136.         mov     bx,word ptr cs:[Handle]
  137.         int     21h
  138.  
  139.         call    Print
  140.         db      'Extracting file completed.$'
  141.  
  142. New60_  endp
  143.  
  144. ; ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  145. ;
  146. ; Beginning of activation code
  147.  
  148. Begin:  mov     ah,009h
  149.         lea     dx,M_Prog               ; 'DeIce - A program to extract...'
  150.         int     21h                     ; Display $-terminated string at ds:dx
  151.  
  152.         mov     ax,03560h
  153.         int     21h
  154.  
  155.         mov     word ptr [Old60],bx
  156.         mov     word ptr [Old60+2],es   ; Store old vector
  157.  
  158.         mov     ax,02560h
  159.         lea     dx,New60
  160.         int     21h
  161.  
  162.         push    cs
  163.         pop     es
  164.  
  165.         mov     si,00080h               ; Count of chars on CommandLine
  166.         lodsb
  167.         or      al,al
  168.         jnz     FetchName
  169.  
  170.         call    Print
  171.         db      'No file specified.$'
  172.  
  173. FetchName:
  174.         cld
  175.         mov     di,00082h               ; Command line start in PSP
  176.         mov     al,00Dh                 ; Search for end of line ( 00Dh )
  177.         mov     cx,007Fh                ; Maximum size of commandline
  178.         repnz   scasb
  179.  
  180.         dec     di
  181.         mov     al,000h
  182.         stosb                           ; Repace it with 0, to make it ASCIIZ
  183.  
  184.         mov     ax,03D00h
  185.         mov     dx,00082h
  186.         int     21h
  187.  
  188.         jnb     Opened
  189.  
  190.         call    Print
  191.         db      'Unable to open specified file.$'
  192.  
  193. Opened: mov     word ptr Handle,ax
  194.  
  195.         mov     ax,cs
  196.         add     ax,((CODEEND-CODESTART) shr 4) + 16     ; Stack space
  197.         mov     ds,ax
  198.  
  199.         lea     sp,NEWSTACK
  200.  
  201.         mov     ah,03Fh
  202.         mov     bx,word ptr cs:[Handle]
  203.         mov     cx,0FFFFh               ; Maximum size of COM file
  204.         mov     dx,00100h
  205.         int     21h                     ; Read cx bytes from handle bx to ds:dx
  206.  
  207.         mov     ah,03Eh
  208.         mov     bx,word ptr cs:[Handle]
  209.         int     21h                     ; Close file handle in bx
  210.  
  211.         push    ds
  212.         pop     es
  213.  
  214.         mov     cx,AlgorithmSize
  215.         mov     al,0D0h
  216.         mov     di,00100h
  217. Scan1:  repnz   scasb                   ; Search for al in es:[di]
  218.         jcxz    NotIce
  219.         cmp     word ptr es:[di],0F8E2h ; The LOOP we are searching
  220.         jne     Scan1
  221.  
  222.         mov     ax,060CDh               ; Replace with INT 60
  223.         stosw
  224.  
  225.         push    es
  226.         mov     ax,0100h
  227.         push    ax
  228.         retf                            ; Jump to COM program
  229.  
  230. ; ***************************************************************************
  231.  
  232.  
  233. NotIce: call    Print
  234.         db      'Program is not compressed under ICE.$'
  235.  
  236. ; ***************************************************************************
  237.  
  238. Print   proc    near
  239.  
  240.         push    cs
  241.         pop     ds
  242.  
  243.         mov     ah,009h
  244.         pop     dx
  245.         int     21h
  246.  
  247.         mov     ah,009h
  248.         lea     dx,CrLf
  249.         int     21h
  250.  
  251.         mov     ax,02560h
  252.         lea     dx,Old60
  253.         int     21h
  254.  
  255.         mov     ah,04Ch
  256.         int     21h                     ; Terminate program
  257.  
  258. Print   endp
  259.  
  260. ; ***************************************************************************
  261.  
  262. CODEEND         EQU     $
  263.  
  264. NEWSTACK        EQU     CODEEND+04Dh
  265.  
  266.         end     Start
  267.